package org.leveryd.controller;

import org.leveryd.dao.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;


@Controller
public class testGetRequest {
    @ResponseBody
    @RequestMapping("/testGetRequest")
    public String testGetRequest() {
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if (requestAttributes != null) {
            HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
            if (request != null){
                String url = String.format("【%s】", request.getRequestURL().toString());
                return url;
            }
        }
        return "hi";
    }

    //@PostMapping("/testPostDataAutoBinding")
    @ResponseBody
    @RequestMapping("/testPostDataAutoBinding")
    public String testPostDataAutoBinding(User user) {
        System.out.println(user.getUsername());
        return "hi";
    }
}
